//var service_ip = "https://www.lazykitchen.cn/";
var service_ip = "https://127.0.0.1:9876/";
function url(inter){
    return service_ip + inter;
}


function remote_call(cmd, data, who){
    var token = wx.getStorageSync('token');
    if( token )
        data["token_key"] = token;
    wx.request({
        method:"POST",
        url: url(cmd),
        data: data,
        header: {
            'content-type': 'application/json'
        },
        success: function(res) {            
            who.on_request_complate(cmd, res.data.data, res.data.status ,res.data.message);            
        },
        fail:function(res){
            who.on_request_complate(cmd, undefined, res.errMsg, false);
        }
    })
}

function upload(file, data, who){
     wx.uploadFile({
        url: url("image/uploader"),
        filePath: file,
        name: 'file',
        formData:data,
        success: function(res) {            
            who.on_upload_complate(file, res.data.data, res.data.status ,res.data.message);            
        },
        fail:function(res){
            who.on_upload_complate(file, undefined, 203, res.errMsg);
        }
    })
}


module.exports = {
  remote_call: remote_call,
  upload:upload
}
